﻿using B.S.DataBase.MyProject.Domain.Management;
using B.S.DataBase.MyProject.ErrorCode;
using MediatR;
using MedicalPCTerminal.Write.API.Appcation.Commands.Management;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace MedicalPCTerminal.Write.API.Controllers
{
    /// <summary>
    /// 管理控制器，处理健康报告和随访管理相关操作
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ManagementController : ControllerBase
    {
        /// <summary>
        /// 日志
        /// </summary>
        private readonly ILogger<ManagementController> logger;
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="logger">日志</param>
        /// <param name="mediator">中介者</param>
        public ManagementController(ILogger<ManagementController> logger, IMediator mediator)
        {
            this.logger = logger;
            this.mediator = mediator;
        }
        /// <summary>
        /// 新增健康报告
        /// </summary>
        /// <param name="request">添加报告命令</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>API结果</returns>
        [HttpPost]
        public async Task<APIResult<object>> Handle(AddReportsCommand request, CancellationToken cancellationToken)
        {
            try
            {
                return await mediator.Send(request, cancellationToken);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 删除报告
        /// </summary>
        /// <param name="request">删除报告命令</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>API结果</returns>
        [HttpDelete]
        public async Task<APIResult<object>> DelReports([FromQuery]DelReportsCommand request, CancellationToken cancellationToken)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 修改报告状态
        /// </summary>
        /// <param name="request">更新报告命令</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>API结果</returns>
        [HttpPut]
        public async Task<APIResult<object>> UpdateReports(UpdateReportsCommand request, CancellationToken cancellationToken)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 添加随访管理
        /// </summary>
        /// <param name="request">添加基础信息命令</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>API结果</returns>
        [HttpPost]
        public Task<APIResult<object>> AddBasic(AddBasicCommand request, CancellationToken cancellationToken)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 修改失访管理
        /// </summary>
        /// <param name="request">更新基础信息命令</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>API结果</returns>
        [HttpPut]
        public Task<APIResult<object>> Handle(UpdateBasicCommand request, CancellationToken cancellationToken)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 添加随访管理
        /// </summary>
        /// <param name="request">添加随访命令</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>API结果</returns>
        [HttpPost]
        public Task<APIResult<object>> AddFollow(AddFollowCommand request, CancellationToken cancellationToken)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
